<?php
	include_once 'BaseModel.php';
	include_once 'PostDAO.php';
	include_once 'UserDAO.php';
	
	class MainModel extends BaseModel {
		public function getData($params) {
			$data->pageOwner = $params->pageOwner;
			$data->user = UserDAO::getInstance()->getUser($params->pageOwner); 
			$data->loggedUserName = Session::getLoggedUserName();
			$postsCount = 20 + 1; //TODO: zastąpić 20 posts per page
			if($data->user != null) {
				$pPosts = PostDAO::getInstance()->getPosts($data->user->getId(), 0, $params->begin, $postsCount);
				 //TODO: 0 zastąpić display level,
			} else {
				$pPosts = PostDAO::getInstance()->getPosts(-1, 0, $params->begin, $postsCount); //TODO: 0 zastąpić display level,
			}
			$data->posts = $pPosts->getPosts();
			$data->maxId = $pPosts->getMaxId();
			if(count($data->posts) == $postsCount) {
				$data->nextPage = true;
				$data->nextPageFirstPost = $data->posts[$postsCount-1]->getId();
				unset($data->posts[$postsCount-1]);
			} else
				$data->nextPage = false;
			return $data; 
		}
	}
?>